package domain;

import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

import utils.StringUtils;
import utils.StringUtils.MyStringBuffer;

public class MyDate {

	Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"),
			Locale.CHINA);

	int year;
	int month;
	int day;

	int hour;
	int minute;
	int second;

	int millliSecond;

	public MyDate() {
		build(System.currentTimeMillis());
	}

	public MyDate(long timeMillis) {
		build(timeMillis);
	}

	public void build(long timeMillis) {
		this.cal.setTimeInMillis(timeMillis);

		this.year = cal.get(Calendar.YEAR);
		this.month = cal.get(Calendar.MONTH) + 1;
		this.day = cal.get(Calendar.DAY_OF_MONTH);

		this.hour = cal.get(Calendar.HOUR_OF_DAY);
		this.minute = cal.get(Calendar.MINUTE);
		this.second = cal.get(Calendar.SECOND);

		this.millliSecond = cal.get(Calendar.MILLISECOND);

	}

	public Calendar getCal() {
		return cal;
	}

	public int getYear() {
		return year;
	}

	public int getMonth() {
		return month;
	}

	public int getDay() {
		return day;
	}

	public int getHour() {
		return hour;
	}

	public int getMinute() {
		return minute;
	}

	public int getSecond() {
		return second;
	}

	public int getMillliSecond() {
		return millliSecond;
	}

	public static void main(String[] args) {
		MyDate date = new MyDate();
		System.out.println(date);

	}

	@Override
	public String toString() {
		MyStringBuffer msb = StringUtils.getNewMyStringBuffer();

		msb.addBlank(getYear()).addBlank(getMonth()).addBlank(getDay())
				.addBlank(getHour()).addBlank(getMinute())
				.addBlank(getSecond()).addBlank(getMillliSecond());

		return msb.getStringAndClose();
	}

}
